package com.yyq.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyq.eduservice.client.Vodclient;
import com.yyq.eduservice.entity.EduVideo;
import com.yyq.eduservice.mapper.EduVideoMapper;
import com.yyq.eduservice.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author yyq
 * @since 2021-04-15
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {
     @Autowired
     private Vodclient vodclient;
    @Override
    public void deleteByCourseId(String courseId) {
        QueryWrapper<EduVideo> wrapper1=new QueryWrapper<>();
        wrapper1.eq("course_id",courseId);
        wrapper1.select("video_source_id");
        List<EduVideo> list = baseMapper.selectList(wrapper1);
        List<String> videoList=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String videoSourceId=list.get(i).getVideoSourceId();
            //因为有的视频id为空　判断一下
            if(videoSourceId!=null){
                videoList.add(videoSourceId);
            }
        }
        //传入的集合不为空就不用远程调用了
        if(videoList!=null){
            vodclient.deleteMoreALiYunVideo(videoList);
        }
        QueryWrapper<EduVideo> wrapper=new QueryWrapper<>();
        wrapper.eq("course_id",courseId);
        baseMapper.delete(wrapper);
    }
}
